﻿using System;
using System.Configuration;
using System.Text;
using AppCommon;
using Controller;

public partial class Dich_vu : System.Web.UI.Page
{
    public static string urlWebsite = ConfigurationManager.ConnectionStrings["URLWebsite"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {            
            int id = GetIdLoaiDiVu();
            BindSubDichvu(id);
            BindQuangCao05(Constants.QC5);
        }
    }

    public void BindSubDichvu(int idLoaiDv)
    {
        var controller = new VYC05Controller();
        var model = controller.GetByIdLoaiChuyenMuc(idLoaiDv);

        if (model.Count > 0)
        {
            repeaterDivu.DataSource = model;
            repeaterDivu.DataBind();
        }
    }

    public int GetIdLoaiDiVu()
    {
        var controller = new VYC04Controller();
        var model = controller.GetByUniqueId(AppCommon.Common.ConvertToUnSign(Constants.CM_DICHVU));
        return model.Count > 0 ? model[0].Id : 0;
    }

    public string BinDataSubMedia(int idSubMedia)
    {
        var sb = new StringBuilder();

        var controller = new VYC06Controller();
        var model = controller.GetBySubLoaiCm(idSubMedia, 1);
        if (model.Count > 0)
        {
            sb.Append("<div class=\"google-plus-social\">");
            sb.Append("<div class=\"g-plusone\" data-size=\"medium\" data-href=\"" + urlWebsite + "tintuc/" +
                      model[0].UniqueId + "\"></div>");
            sb.Append(
                "<a class=\"fb-like\" data-layout=\"button_count\" data-action=\"like\" data-show-faces=\"true\" data-share=\"true\" data-href=\"" +
                urlWebsite + "tintuc/" + model[0].UniqueId + "\"></a></div>");
            sb.Append("<h4><a href=\"tintuc/" + model[0].UniqueId + "\">" + model[0].TieuDe + " </a></h4>");
            sb.Append("<p class=\"gray-color-note\">");
            sb.Append("<i class=\"fa fa-calendar\"></i> Ngày viết:" + model[0].NgayCapNhat.ToString("dd/mm/yyyy"));
            sb.Append(" <i class=\"fa fa-user\"></i> Người viết: " + model[0].TacGia);
            sb.Append(" <i class=\"fa fa-eye\"></i> Lượt xem: " + model[0].LuotXem + " </p>");
            sb.Append("<p><a href=\"../tintuc/" + model[0].UniqueId +
                      "\"><img class=\"display-100-percent\" src=\"Upload/tintuc/" + model[0].AnhDaiDien +
                      "\" alt=\"" + model[0].AnhDaiDien + "\" /></a></p>");
            sb.Append("<p class=\"text-justify\">" + Common.LimitWords(model[0].TomTat) + "</p>");

            if (model.Count > 1)
            {
                sb.Append("<ul>");
                // lap
                foreach (var modelVyc06 in model)
                {
                    sb.Append("<li><a href=\"../tintuc/" + modelVyc06.UniqueId + "\">" + modelVyc06.TieuDe + "</a></li>");
                }
                sb.Append("</ul>");
            }
        }
        else
        {
            sb.Append("Dữ liệu chưa được cập nhật");
        }
        return sb.ToString();
    }

    public void BindQuangCao05(string uniqueid)
    {
        var controller = new VYC05Controller();
        var model = controller.GetByUniqueId(uniqueid);

        // Get quang cao 1
        if (model.Count > 0)
        {
            var controller1 = new VYC06Controller();
            var model1 = controller1.GetBySubLoaiCm(model[0].Id, 1);

            // Set link and image
            if (model1.Count > 0)
            {
                linkQuangcao02.NavigateUrl = model1[0].LienKet;
                imgQuangcao02.ImageUrl = Constants.UPLOAD_TINTUC + model1[0].AnhDaiDien;
                imgQuangcao02.AlternateText = model1[0].TieuDe;
                imgQuangcao02.ToolTip = model1[0].TieuDe;
            }

        }
    }

    public int GetIdQuangcaoVYC1(int number)
    {
        var controller = new VYC05Controller();
        var model = controller.GetByUniqueId(Constants.SUB_QUANG_CAO + number);
        if (model.Count > 0)
            return model[0].Id;
        return 0;
    }

}